//
//  DataCheck.m
//  ctrj_Nxswt
//
//  Created by 费成 on 15/9/20.
//  Copyright (c) 2015年 费成. All rights reserved.
//

#import "DataCheck.h"

@implementation DataCheck

+ (BOOL) isValidString:(id)input
{
    if (!input) {
        return NO;
    }
    
    if ((NSNull *)input == [NSNull null]) {
        return NO;
    }
    
    if (![input isKindOfClass:[NSString class]]) {
        return NO;
    }
    
    if ([input isEqualToString:@""]) {
        return NO;
    }
    
    if ([input length] <= 0) {
        return NO;
    }
    return YES;
}

+ (BOOL) isValidDictionary:(id)input
{
    if (!input) {
        return NO;
    }
    
    if ((NSNull *)input == [NSNull null]) {
        return NO;
    }
    
    if (![input isKindOfClass:[NSDictionary class]]) {
        return NO;
    }
    
    if ([input count] <= 0) {
        return NO;
    }
    
    return YES;
}

+ (BOOL) isValidArray:(id)input
{
    if (!input) {
        return NO;
    }
    
    if ((NSNull *)input == [NSNull null]) {
        return NO;
    }
    
    if (![input isKindOfClass:[NSArray class]]) {
        return NO;
    }
    
    if ([input count] <= 0) {
        return NO;
    }
    
    return YES;
}

//利用正则表达式验证

+(BOOL)isValidateEmail:(NSString *)email
{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

//判断手机号
+(BOOL)isValidatePhone:(NSString *)phone
{
    NSString *regex = @"^((1[0-9][0-9]))\\d{8}$";
//    NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0-9]))\\d{8}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:phone];
    if (!isMatch) {
        return NO;
    }
    return YES;
}

+(BOOL) isInteger:(NSString *)input
{
    NSString *regex = @"[0-9]{1,9}";
    NSPredicate *regTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [regTest evaluateWithObject:input];
    //    if (strcmp([clmnObj objCType], @encode(int)) == 0) {
    //        clmnValue = [NSString stringWithFormat:@"%d", [rs boolForColumnIndex:idx]];
    //    }
}
@end
